<%@page contentType="text/html; charset=UTF-8"%>
<%@ page import="com.qingneng.budget.security.CurrentUser" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>合同信息</title>
<%@ include file="../../common/common.jsp"%>

<script type="text/javascript">


function statusFormatter(value,row,index){
	if (value==0){
		var s = '新建';
		return s;
	}
	if (value==1){
		var s = '已编制';
		return s;
	}
	if (value==2){
		var s = '已审核';
		return s;
	}
	if (value==3){
		var s = '已签订';
		return s;
	}
}


var url;
function newCt_info() {

	$('#dlg').dialog('open').dialog('setTitle', '新增合同');
	jQuery('#company_code').combobox({
	    url:'<%=basePath%>jsp/GetJson.jsp?type=companyinfoList',
	    valueField:'companyCode',
	    textField:'companyName'
	});
	$('#fm').form('clear');
}
function editCt_info() {
	var row = $('#dg').datagrid('getSelected');
	
	
	/*var dataRows = new Array();
	
	 for( var key in row){
		var value = row[key];
		//alert('key:'+key+" value :"+row[key]);
		var ke_v = '\"'+'contractInfo.' + key+'\"'+ + "\\:" + '\"'+row[key]+'\"';
		dataRows.push(ke_v);
	}
	alert(dataRows);
	var data = "\{" + dataRows+"\}";
	
	var JsonData = eval(data);
	alert(JsonData);
	*/
	
	if (row) {
		//alert(row.contractNo);
		$('#dlg').dialog('open').dialog('setTitle', '编辑合同');
		
		jQuery('#company_code').combobox({
		    url:'<%=basePath%>jsp/GetJson.jsp?type=companyinfoList',
		    valueField:'companyCode',
		    textField:'companyName'
		});
		$('#company_code').combobox('setValue',row.companyCode);
		$('#fm').form('load', row);
		
	}
}
function saveCt_info() {
	$('#fm').form('submit', {
		url : '<%=basePath %>saveContractAction!saveData.do',
		onSubmit : function() {
			return $(this).form('validate');
		},
		success : function(result) {
			var result = eval('(' + result + ')');
			//alert(result);
			if (result.message=='success') {
				$('#dlg').dialog('close'); // close the dialog
				$('#dg').datagrid('reload'); // reload the user data
		} else {
		$.messager.show( {
			title : '错误提示',
			msg : result.message
		});
	}
}
	});
}
function removeCt_info() {
	var row = $('#dg').datagrid('getSelected');
	if (row) {
		$.messager.confirm('Confirm',
				'请确认是否删除该合同信息?', function(r) {
					if (r) {
						$.post('<%=basePath %>saveContractAction!destoryData.do', {
							id : row.id
						}, function(result) {
							if (result.message=='success') {
								$('#dg').datagrid('reload'); // reload the user data
							} else {
								$.messager.show( { // show error message
										title : '错误提示',
										msg : result.message
										});
							}
						}, 'json');
					}
				});
	}
}
</script>
	</head>
	<body>
	
<%
 String account = CurrentUser.getUser().getUseraccount();
%>

		<table id="dg" title="合同信息" class="easyui-datagrid"
			style="width: 1130px; height: 420px" url="<%=basePath %>contractInfoAction!loadData.do"
			toolbar="#toolbar" pagination="true" rownumbers="true"
			fitColumns="true" singleSelect="true" >
			<thead>
				<tr>
					<th field="contractNo" width="30" align="center">
						合同编号
					</th>
					<th field="contractName" width="50" align="center">
						合同名称
					</th>
					<th field="aurhorizedPerson" width="30" align="center">
						编制人员
					</th>
					<th field="auditPerson" width="30" align="center">
						审核人员
					</th>
					<th field="auditTime" width="30" align="center">
						审核时间
					</th>
					<th field="signPerson" width="30" align="center">
						签订人
					</th>
					<th field="signTime" width="30" align="center">
						签订时间
					</th>
					<th field="customerName" width="50" align="center">
						客户名称
					</th>
					<th field="customerContactPerson" width="40" align="center">
						客户联系人
					</th>
					<th field="customerContactPhone" width="40" align="center">
						客户联系电话
					</th>
					<th field="contractStatus" width="20" align="center" formatter="statusFormatter">
						状态
					</th>
					<th field="createTime" width="30" align="center">
						创建时间
					</th>
					<th field="budgetPrice" width="30" align="center">
						预算价格
					</th>
					<th field="contractPrice" width="30" align="center">
						合同价格
					</th>
					<th field="contract_remark" width="50" align="center">
						合同说明
					</th>
				</tr>
			</thead>
		</table>

		<div id="toolbar">
			<a href="#" class="easyui-linkbutton" iconCls="icon-add" 
				onclick="newCt_info()">新建</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-edit"
				 onclick="editCt_info()">编辑</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-remove"
				 onclick="removeCt_info()">删除</a>
		</div>

		<div id="dlg" class="easyui-dialog"
			style="width: 700px; height: 380px; " closed="true"
			buttons="#dlg-buttons">
			<div class="ftitle">
				合同信息
			</div>
			<form id="fm" method="post" >
				<table  style="border:1px solid #b3dfda;width:600px">
				
					<tr colspan="2" style="display: none">
						
						<td>
							<div class="fitem">
								<label>
									ID:
								</label>
								<input name="id" class="easyui-validatebox" >
							</div>
						</td>
						
					</tr>
					
					<tr>
						
						<td>
							<div class="fitem">
								<label>
									合同编号:
								</label>
								<input name="contractNo" class="easyui-validatebox" required="true">
							</div>
						</td>
						<td>
							<div class="fitem">
								<label>
									合同名称:
								</label>
								<input name="contractName" class="easyui-validatebox" required="true">
							</div>
						</td>

					</tr>

					<tr>
						<td>
							<div class="fitem">
								<label>
									编制人员:
								</label>
								<input name="aurhorizedPerson">
							</div>
						</td>
						<td>
							<div class="fitem">
								<label>
									客户名称:
								</label>
								<input name="customerName" >
							</div>
						</td>
					</tr>
					<tr>
						<td></td>
						<td></td>
					</tr>

					<tr>
					
						<td >
						<div class="fitem">
									<label>
										客户联系人:
									</label>
									<input name="customerContactPerson" >
						</div>
								
	
						</td>
					
						<td >
							<div class="fitem">
										<label>
											客户联系电话:
										</label>
										<input name="customerContactPhone" >
							</div>
								
	
						</td>
					</tr>
					
					<tr>	
					
					
						<td>
							<div class="fitem">
								<label>
									所属公司:
								</label>
								<!--  <input name="company_code" >
								<input class="easyui-combobox" name="company_code" url="combobox_data.json" 
			                      valueField="id" textField="text" multiple="true" panelHeight="auto">
			                      -->
			                      <select id="company_code" class="easyui-combotree"
								name="company_code" style="width: 133px;"></select>
							</div>
						</td>
						<td >

							<div class="fitem">
								<label>
									合同说明:
								</label>
								<textarea  cols="30" rows=1 name="contract_remark"></textarea>
							</div>
						</td>
						
						
					</tr>
				

				</table>

			</form>
		</div>
		<div id="dlg-buttons">
			<a href="#" class="easyui-linkbutton" iconCls="icon-ok"
				onclick="saveCt_info()">保存</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-cancel"
				onclick="javascript:$('#dlg').dialog('close')">取消</a>
		</div>
	</body>
</html>